<!DOCTYPE html>
<html lang="en">
  <head>
    <meta charset="UTF-8" />
    <meta name="viewport" content="width=device-width, initial-scale=1.0" />
    <title>Document</title>
    <script>
      // window.onload = function(){
      //   var img1 = document.querySelector('#img1')
      //   img1.onerror = function(){
      //     console.log(123)
      //   }
      // }
    </script>
  </head>
  <body>
    <div id="app">
      <img v-imgerror="默认图片路径" src="image.gif" onerror="alert('The image could not be loaded.')">
    </div>
    <script src="./node_modules/vue/dist/vue.js"></script>
    <script>
      Vue.directive('imgerror',{
        inserted(dom,options){
          dom.onerror = function(){
            dom.src = options.value
          }
        }
      })
      var vm = new Vue({
        el: '#app',
        data: {},
        methods: {},
      })

    </script>
  </body>
</html>
